<template>
  <div v-if="partListCon">
    <!-- {{ selnews }}
    {{ activeBnnerIndex }}
    {{ partListCon }} -->
    <el-form ref="form" :model="partListCon" label-width="110px" size="small">
      <el-form-item label="是否显示">
        <el-switch class="zdySwith" :width="82" :value="partListCon.show" active-color="#13ce66" @change="updateInput($event, 'show')"
            inactive-color="#ffffff" active-text="显示" inactive-text="隐藏" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>

      <el-form-item label="标题">
        <el-input @input="updateInput($event, 'title')" :value="partListCon.title" placeholder="请输入标题">
        </el-input>
      </el-form-item>
      <el-form-item label="副标题">
        <el-input @input="updateInput($event, 'title_en')" :value="partListCon.title_en" placeholder="请输入副标题">
        </el-input>
      </el-form-item>

      <el-form-item label="资讯分类选择">
        <el-cascader :options="data" :props="optionProps" :show-all-levels="false" v-model="selnews" size="small" change-on-select placeholder="新闻分类"
            clearable @change="change_selnews"></el-cascader>
      </el-form-item>
      <el-divider></el-divider>
    </el-form>
  </div>
</template>

<script>
import uploadpic from "@/components/page/pic/up_pic";
import LinkMenu from "@/components/currency/Link_menu.vue";
import { mapState, mapGetters } from "vuex";
export default {
  data () {
    return {
      selnews: [],
      optionProps: {
        value: "id",
        label: "title",
        children: "z"
      },
      data: [],
      xzshow: false,
      currentPage1: 1,
      pageSize: 10,
      show: false,
      list: {
        data: []
      },
      style_option: [
        {
          label: "一行1个",
          value: "0"
        },
        {
          label: "一行2个",
          value: "1"
        }
      ]
    };
  },

  computed: {
    ...mapGetters(["partListConConss"]),
    ...mapState({
      active: state => state.modulePage.active,
      activeBnnerIndex: state => state.modulePage.bannerNowIndex,
      allbanner: state => state.modulePage.allbanner
    }),
    partListCon () {
      if (this.activeBnnerIndex >= 0) {
        return this.allbanner[this.activeBnnerIndex];
      } else {
        return {};
      }
    }
  },
  components: {
    uploadpic,
    LinkMenu
  },
  created () {
    this.getNewFenLeiTree();
  },
  mounted () { },
  methods: {
    change_selnews (arr) {
      if (arr == undefined) return;
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: arr[0]
      });
      //   this.news_form.pageis_show_new_cate = arr[0];
    },
    getNewFenLeiTree () {
      var params = {};
      params.parent_id = "0";
      this.$api.getNewsFenlei.getNewsList(params).then(res => {
        if (res.data.code == 200 && res.data.status == 1 && res.data.result) {
          this.data = res.data.result;
        }
      });
    },
    delshopitem (item, index) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: index
      });
      var val = this.partListCon.text.replace(item.id + "@", "");

      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val
      });
    },
    closeshow () {
      this.show = false;
      this.xzshow = false;
    },
    setId (row) {
      this.show = false;
      this.xzshow = false;
      console.log(row);
      var val = this.partListCon.text + row.id + "@";
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val
      });
      this.$store.commit("addbanner_shopitem", {
        title: row.title,
        piclink: row.piclink
      });
    },

    showDio () {
      this.show = true;
      setTimeout(() => {
        this.xzshow = true;
      }, 100);
    },
    del_banneritem (i) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: i
      });
    },
    set_banneritem_val (pic, i, name) {
      this.$store.commit("set_sonbanner_item", {
        key: this.activeBnnerIndex,
        name: name,
        index: i,
        val: pic
      });
    },

    toCheckArrIndex (i, status) {
      //排序

      var index2 = "";
      if (status == "up") {
        index2 = i - 1;
      } else {
        index2 = i + 1;
      }

      this.$store.commit("sortbanner_son", {
        key: this.activeBnnerIndex,
        index1: i,
        index2: index2,
        status: status
      });
    },
    updateInput (val, name) {
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: name,
        val: val
      });
    },

    getSendRow (row) {
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      var result = this.$fnc.getSendRow(row);
      var obj = {};
      obj.key = this.activeBnnerIndex;
      console.log(result);
      if (result.title != "自定义链接") {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: result.desc
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: result.links
        });
      } else {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: "自定义链接"
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: " "
        });
      }
    }
  },
  watch: {}
};
</script>

<style scoped lang="less"></style>
